package com.ruoyi.web.controller.order;


import cn.hxzy.common.AbnormalType;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hxzy.order.entity.TtAbnormalImage;
import com.hxzy.order.entity.TtAbnormalReporting;
import com.hxzy.order.service.TtAbnormalImageService;
import com.hxzy.order.service.TtAbnormalReportingService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.DataSourceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mingqian.Wu
 * @since 2023-06-27
 */
@RestController
@RequestMapping("/ttAbnormalReporting")
@DataSource(DataSourceType.ORDER)
public class TtAbnormalReportingController {

    @Autowired
    private TtAbnormalReportingService ttAbnormalReportingService;

    @Autowired
    private TtAbnormalImageService ttAbnormalImageService;

    @Value("${oss-img-path}")
    private String ossImgPath;

    @GetMapping("/getAbnormalReporting/{id}")
    @Anonymous
    public AjaxResult getAbnormalReporting(@PathVariable String id) {
        QueryWrapper<TtAbnormalReporting> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("waybill_id", id);
        TtAbnormalReporting one = ttAbnormalReportingService.getOne(queryWrapper);
        if (one != null) {
            List<TtAbnormalImage> list = ttAbnormalImageService.getList(one.getExceptionId());
            one.setExceptionTypeName(AbnormalType.getAbnormalStatusValue(one.getExceptionType()));
            if (list.size() > 0) {
                List<String> list1 = new ArrayList<>();
                list.stream().forEach(item -> {
                    item.setImagePath(ossImgPath + item.getImagePath());
                    list1.add(item.getImagePath());
                });
                one.setImageList(list1);
                return AjaxResult.success(one);
            }
        }

        return AjaxResult.error("暂无异常报告");

    }


}

